import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)


const routes = [{
  path: '/',
  redirect: '/home'
},
{
  path: '/home',
  component: () => import( /*webpackChunkName:"home" */ '../views/Home/Home.vue'),
  // isShowNav 表示 Tabbar是否显示
  meta: {
    isShowNav: true,
    til: "首页"
  }
},
{
  path: '/categary',
  component: () => import( /*webpackChunkName:"categary" */ '../views/Categary/Categary.vue'),
  meta: {
    isShowNav: true,
    til: "分类"
  }
},
{
  path: '/cart',
  component: () => import( /*webpackChunkName:"cart" */ '../views/Cart/Cart.vue'),
  meta: {
    isShowNav: true,
    til: "购物车"
  }
},
{
  path: '/user',
  component: () => import( /*webpackChunkName:"user" */ '../views/User/User.vue'),
  meta: {
    isShowNav: true,
    til: "我的"
  }
},
{
  path: '/login',
  component: () => import( /*webpackChunkName:"login" */ '../views/Login/Login.vue'),
  meta: {
    isShowNav: false,
    til: "登录"
  }
},
{
  path: '/info/:productId',
  component: () => import( /*webpackChunkName:"info" */ '../views/Info/Info.vue'),
  meta: {
    isShowNav: false, // 控制的是是否展示下边的导航栏
    til: "商品详情"
  }
},
{
  path: '/addressList',
  component: () => import( /*webpackChunkName:"info" */ '../views/Address/AddressList.vue'),
  meta: {
    isShowNav: false, // 控制的是是否展示下边的导航栏
    til: "地址列表"
  }
}, {
  path: '/addressEdit',
  component: () => import( /*webpackChunkName:"info" */ '../views/Address/AddressEdit.vue'),
  meta: {
    isShowNav: false, // 控制的是是否展示下边的导航栏
    til: "地址管理"
  }
},
{
  path: '/create-order',
  component: () => import( /*webpackChunkName:"createOrder" */ '../views/CreateOrder/CreateOrder.vue'),
  meta: {
    isShowNav: false,// 控制的是是否展示下边的导航栏
    til: "生成订单"
  }
}, {
  path: '/order',
  component: () => import( /*webpackChunkName:"order" */ '../views/Order/Order.vue'),
  meta: {
    isShowNav: false, // 控制的是是否展示下边的导航栏
    til: "订单页"
  }
},
]


const router = new VueRouter({
  routes
})

// 前置守卫
router.beforeEach((to, from, next) => {
  document.title = to.meta.til || "码路严选"
  next()
})

export default router
